<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">

      <el-form-item label="主体名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入主体名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="注册⼿机号" prop="mobilePhone">
        <el-input
          v-model="queryParams.mobilePhone"
          placeholder="请输入注册⼿机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="注册时间" prop="registerTime">
        <el-date-picker clearable
          v-model="queryParams.registerTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择注册时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="营业执照 " prop="businessFlag">
        <el-input
          v-model="queryParams.businessFlag"
          placeholder="请输入是否有营业执照 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--省市区级联组件-->
      <el-form-item label="省" prop="province">
        <el-select v-model='queryParams.province' filterable placeholder="请选择省" clearable >
          <el-option v-for='(temp,index) in mixinsProvinceList' :value="temp.name" :key='index' :label="temp.name"
                     @click.native='mixinsProvinceChange(temp.code)'/>
        </el-select>
      </el-form-item>
      <el-form-item label="市" prop="city">
        <el-select v-model='queryParams.city' filterable placeholder="请选择市(请先选择省)" clearable >
          <el-option v-for='(temp,index) in mixinsCityList' :value="temp.name" :key='index' :label="temp.name"
                     @click.native='mixinsCityChange(temp.code)'/>
        </el-select>
      </el-form-item>
      <el-form-item label="区/县" prop="area">
        <el-select v-model='queryParams.area' filterable placeholder="请选择区/县(请先选择市)" clearable >
          <el-option v-for='(temp,index) in mixinsAreaList' :value="temp.name" :key='index' :label="temp.name" @click.native='mixinsAreaChange(temp.code)' />
        </el-select>
      </el-form-item>
      <el-form-item label="乡镇/街道" prop="country" >
        <el-select v-model='queryParams.country' filterable placeholder="请选择街道(请先选择区/县)" clearable >
          <el-option v-for='(temp,index) in mixinsStreetList' :value="temp.name" :key='index' :label="temp.name"/>
        </el-select>
      </el-form-item>

      <el-form-item label="主体类型" prop="mainType">
        <el-input
          v-model="queryParams.mainType"
          placeholder="请输入主体类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="法⼈姓名" prop="legalPersonName">
        <el-input
          v-model="queryParams.legalPersonName"
          placeholder="请输入法⼈姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="联系电话" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['nongit:perfect:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" :data="perfectList" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="注册⼿机号" align="center" prop="mobilePhone" width="120"/>
      <el-table-column label="是否有营业执照 " align="center" prop="businessFlag" width="120"/>
      <el-table-column label="主体名称" align="center" prop="companyName" width="200"/>
      <el-table-column label="法⼈姓名" align="center" prop="legalPersonName" />
      <el-table-column label="统⼀社会信⽤代码" align="center" prop="creditCode"  width="160"/>
      <el-table-column label="证件号码" align="center" prop="idNumber" width="150"/>
      <el-table-column label="注册资⾦(万元)" align="center" prop="registerMoney" width="160" />
      <el-table-column label="企业成⽴时间" align="center" prop="foundTime" width="180" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.foundTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" align="center" prop="registerTime"/>

      <el-table-column label="联系电话" align="center" prop="phoneNumber" />

      <el-table-column
          align="center"
          prop="address"
          label="详细地址"
          width="300"
          height="50">
          <el-table-column label="省" align="center" prop="province" />
          <el-table-column label="市" align="center" prop="city" />
          <el-table-column label="区/县" align="center" prop="area" />
          <el-table-column label="乡镇/街道" align="center" prop="country" />
          <el-table-column label="详细地址" align="center" prop="detailAddress" />
      </el-table-column>

      <el-table-column label="⾏业类型" align="center" prop="industryType" />
      <el-table-column label="⽣产类型" align="center" prop="produceType" />
      <el-table-column label="营业执照" align="center" prop="businessLicenseUrl" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.businessLicenseUrl" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="认证资质" align="center" prop="certificationQualificationUrl" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.certificationQualificationUrl" :width="50" :height="50"/>
        </template>
      </el-table-column>

      <el-table-column label="地址编码" align="center" prop="addressCode" />
      <el-table-column label="主体类型" align="center" prop="mainType" />
      <el-table-column label="主体身份" align="center" prop="subjectIdentity" />

      <el-table-column label="品牌logo" align="center" prop="logoUrl" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.logoUrl" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="照⽚墙" align="center" prop="photoWall" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.photoWall" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="照⽚墙介绍" align="center" prop="photoMsg" />

      <el-table-column label="审核状态" align="center" prop="examineStatus" />
      <el-table-column label="审核时间" align="center" prop="examineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.examineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="打印合格证" align="center" prop="certificateTitleFlag" />

      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['nongit:perfect:edit']"
          >修改</el-button>
          <el-divider direction="vertical"></el-divider>

          <el-dropdown trigger="click" >
            <el-button
              size="mini"
              type="text"
            >更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu slot="dropdown">


              <el-dropdown-item>
                  <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleExamineStatus(scope.row)"
                >审核</el-button>
              </el-dropdown-item>

              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handlePassword(scope.row)"
                >重置</el-button>
              </el-dropdown-item>

              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['nongit:perfect:remove']"
                >删除</el-button>
              </el-dropdown-item>

            </el-dropdown-menu>
          </el-dropdown>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改⽤户完善信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="⽤户注册表ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入⽤户注册表ID" />
        </el-form-item>
        <el-form-item label="注册⼿机号" prop="mobilePhone">
          <el-input v-model="form.mobilePhone" placeholder="请输入注册⼿机号" />
        </el-form-item>
        <el-form-item label="注册时间" prop="registerTime">
          <el-date-picker clearable
            v-model="form.registerTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择注册时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="主体名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入主体名称" />
        </el-form-item>
        <el-form-item label="法⼈姓名" prop="legalPersonName">
          <el-input v-model="form.legalPersonName" placeholder="请输入法⼈姓名" />
        </el-form-item>
        <el-form-item label="是否有营业执照 " prop="businessFlag">
          <el-input v-model="form.businessFlag" placeholder="请输入是否有营业执照 " />
        </el-form-item>
        <el-form-item label="营业执照" prop="businessLicenseUrl">
          <image-upload v-model="form.businessLicenseUrl"/>
        </el-form-item>
        <el-form-item label="认证资质" prop="certificationQualificationUrl">
          <image-upload v-model="form.certificationQualificationUrl"/>
        </el-form-item>
        <el-form-item label="省" prop="province">
          <el-input v-model="form.province" placeholder="请输入省" />
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-input v-model="form.city" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="区/县" prop="area">
          <el-input v-model="form.area" placeholder="请输入区/县" />
        </el-form-item>
        <el-form-item label="乡镇/街道" prop="country">
          <el-input v-model="form.country" placeholder="请输入乡镇/街道" />
        </el-form-item>
        <el-form-item label="详细地址" prop="detailAddress">
          <el-input v-model="form.detailAddress" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="地址编码" prop="addressCode">
          <el-input v-model="form.addressCode" placeholder="请输入地址编码" />
        </el-form-item>
        <el-form-item label="主体身份" prop="subjectIdentity">
          <el-input v-model="form.subjectIdentity" placeholder="请输入主体身份" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="统⼀社会信⽤代码" prop="creditCode">
          <el-input v-model="form.creditCode" placeholder="请输入统⼀社会信⽤代码" />
        </el-form-item>
        <el-form-item label="证件号码" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="注册资⾦" prop="registerMoney">
          <el-input v-model="form.registerMoney" placeholder="请输入注册资⾦" />
        </el-form-item>
        <el-form-item label="品牌logo" prop="logoUrl">
          <image-upload v-model="form.logoUrl"/>
        </el-form-item>
        <el-form-item label="照⽚墙" prop="photoWall">
          <image-upload v-model="form.photoWall"/>
        </el-form-item>
        <el-form-item label="照⽚墙介绍" prop="photoMsg">
          <el-input v-model="form.photoMsg" placeholder="请输入照⽚墙介绍" />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="企业成⽴时间" prop="foundTime">
          <el-date-picker clearable
            v-model="form.foundTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择企业成⽴时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核未通过原因" prop="examineMsg">
          <el-input v-model="form.examineMsg" placeholder="请输入审核未通过原因" />
        </el-form-item>
        <el-form-item label="审核时间" prop="examineTime">
          <el-date-picker clearable
            v-model="form.examineTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="省平台密码" prop="sptPassword">
          <el-input v-model="form.sptPassword" placeholder="请输入省平台密码" />
        </el-form-item>
        <el-form-item label="省平台账号" prop="sptLoginName">
          <el-input v-model="form.sptLoginName" placeholder="请输入省平台账号" />
        </el-form-item>
        <el-form-item label="是否有省平台权限 0 ⽆，1 有" prop="sptAuth">
          <el-input v-model="form.sptAuth" placeholder="请输入是否有省平台权限 0 ⽆，1 有" />
        </el-form-item>
        <el-form-item label="是否同步到成都市，0：⽆需同步，1：需要同步，2：已同步" prop="isSync">
          <el-input v-model="form.isSync" placeholder="请输入是否同步到成都市，0：⽆需同步，1：需要同步，2：已同步" />
        </el-form-item>
        <el-form-item label="是否打印合格证抬头，0：否，1：是" prop="certificateTitleFlag">
          <el-input v-model="form.certificateTitleFlag" placeholder="请输入是否打印合格证抬头，0：否，1：是" />
        </el-form-item>
        <el-form-item label="历史签名图⽚" prop="signUrl">
          <image-upload v-model="form.signUrl"/>
        </el-form-item>
        <el-form-item label="删除标记 " prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记 " />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog :title="title" :visible.sync="handlePasswordVO" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="登录账号" prop="sptLoginName" width="120" >
          <el-input v-model="form.sptLoginName" placeholder="请输入省平台账号" :disabled="true"/>
        </el-form-item>
        <el-form-item label="登录密码" prop="sptPassword" width="120">
          <el-input v-model="form.sptPassword" placeholder="请输入省平台密码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="handleExamineStatusVO" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="审核状态" prop="examineStatus">
          <el-radio-group v-model="form.examineStatus">
            <el-radio-button :label="0">待审核</el-radio-button>
            <el-radio-button :label="1">不通过</el-radio-button>
            <el-radio-button :label="2">通过</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="examineMsg" width="120">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="form.examineMsg">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listPerfect, getPerfect, delPerfect, addPerfect, updatePerfect } from "@/api/nongit/perfect";
import {AreaMixins} from "@/mixins/AreaMixins";


export default {
  name: "Perfect",
  mixins:[AreaMixins],

  data() {
    return {
      handleExamineStatusVO:false,
      handlePasswordVO:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // ⽤户完善信息表格数据
      perfectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        mobilePhone: null,
        registerTime: null,
        companyName: null,
        legalPersonName: null,
        businessFlag: null,
        businessLicenseUrl: null,
        certificationQualificationUrl: null,
        province: null,
        city: null,
        area: null,
        country: null,
        detailAddress: null,
        addressCode: null,
        produceType: null,
        mainType: null,
        subjectIdentity: null,
        industryType: null,
        phoneNumber: null,
        creditCode: null,
        idNumber: null,
        registerMoney: null,
        logoUrl: null,
        photoWall: null,
        photoMsg: null,
        longitude: null,
        latitude: null,
        foundTime: null,
        examineStatus: null,
        examineMsg: null,
        examineTime: null,
        sptPassword: null,
        sptLoginName: null,
        sptAuth: null,
        isSync: null,
        certificateTitleFlag: null,
        signUrl: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询⽤户完善信息列表 */
    getList() {
      this.loading = true;
      listPerfect(this.queryParams).then(response => {
        this.perfectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        mobilePhone: null,
        registerTime: null,
        companyName: null,
        legalPersonName: null,
        businessFlag: null,
        businessLicenseUrl: null,
        certificationQualificationUrl: null,
        province: null,
        city: null,
        area: null,
        country: null,
        detailAddress: null,
        addressCode: null,
        produceType: null,
        mainType: null,
        subjectIdentity: null,
        industryType: null,
        phoneNumber: null,
        creditCode: null,
        idNumber: null,
        registerMoney: null,
        logoUrl: null,
        photoWall: null,
        photoMsg: null,
        longitude: null,
        latitude: null,
        foundTime: null,
        examineStatus: null,
        examineMsg: null,
        examineTime: null,
        sptPassword: null,
        sptLoginName: null,
        sptAuth: null,
        isSync: null,
        certificateTitleFlag: null,
        signUrl: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加⽤户完善信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPerfect(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改⽤户完善信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePerfect(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.handlePasswordVO = false;
              this.handleExamineStatusVO = false;
              this.getList();
            });
          } else {
            addPerfect(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 密码重置按钮操作 */
    handlePassword(row){
      this.reset();
      const id = row.id || this.ids
      getPerfect(id).then(response => {
        this.form = response.data;
        this.handlePasswordVO = true;
        this.title = "重置密码";
      });
    },

    handleExamineStatus(row){
      this.reset();
      const id = row.id || this.ids
      getPerfect(id).then(response => {
        this.form = response.data;
        this.handleExamineStatusVO = true;
        this.title = "审核";
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除⽤户完善信息编号为"' + ids + '"的数据项？').then(function() {
        return delPerfect(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('nongit/perfect/export', {
        ...this.queryParams
      }, `perfect_${new Date().getTime()}.xlsx`)
    },

    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    }
  }
};
</script>
